← Course index · R314 System & Network
MMIBUT Métiers du Multimédia et de l'Internet · IUT de Vélizy

Lab · Apache web server on Linux

Installing, configuring and securing an Apache HTTP server.

TPhttpdCentOS / RockyWeb

Objective

Know how to install, configure and maintain an HTTP server on Unix.

Hardware & requirements

A PC running CentOS / Rocky Linux, the Apache HTTP server software, a web browser.

Lab assessment: no report required. Take notes; the teacher validates each step as you go.

01Installation or update

Apache is highly modular, which makes it easy to add extensions to the server (PHP module, SSL module…). Install it with all necessary dependencies — package httpd:

# yum install httpd

In the list of files of the httpd package, find:

  1. The path to the httpd executable.
  2. The path to the configuration file httpd.conf.
Reminder: rpm -qa lists all installed packages; rpm -ql httpd lists the files of the package.

02Launch

  1. Start the httpd service with the service command, as usual.
  2. Which URL does your web server respond to?
  3. Test access to your server with a browser.
  4. Check that the httpd service is running by noting its PID.
Show this to the teacher to validate your points!

03Configuration

As root, edit /etc/httpd/conf/httpd.conf — make a backup first. Lines starting with # are comments.

  1. Give your server a name by setting the ServerName variable. What is this name used for?
  2. What would you need to do to reach your server "www.myfirstwebserver.fr" at http://www.myfirstwebserver.fr/?
  3. The Include directive includes other configuration files: which files are included?
  4. The DocumentRoot variable holds the directory where the server's documents are placed.
    • Note its value.
    • Create a sub-folder with your name and change the path so it becomes the new root of your site. Also change the path in the matching <Directory …> section.
    • Put a custom index.html page in the new root directory.
    • Restart Apache with the service command.
    • Test access at http://localhost.
  5. What is the role of the DirectoryIndex variable? What is its value?
  6. Using the official documentation, what is the role of AccessFileName? What is its default value?
  7. Using the official documentation, what are Alias directives used for?

UserDir module

The UserDir module lets users of the host machine create a directory whose documents are published on the web. Configuration file: /etc/httpd/conf.d/userdir.conf.

  1. Change the value of the UserDir variable in the configuration file.
  2. Restart the service with service to apply it.
  3. Create an index.html page in the web directory defined by UserDir for the Unix user account toto.
  4. Run chmod 755 /path/to/home/toto to change permissions (the Apache user needs access).
  5. Restart Apache.
  6. Run setsebool -P httpd_enable_homedirs true (SELinux).
  7. Test access at http://localhost/~toto (note the tilde).

Logs

  1. Look at /etc/httpd/logs/access_log (with tail -f access_log) and /etc/httpd/logs/error_log.
  2. What information do they contain?
  3. How can these files help you debug a site?
Show this to the teacher to validate your points!

04Security

We want to protect access to a directory called secret in /var/www/html/yourname/secret. Add a section at the end of httpd.conf with these directives:

<Directory "/var/www/html/yourname/secret"> Options Indexes AllowOverride None AuthType Basic AuthName "Protected Directory" AuthUserFile /etc/httpd/conf/passwd AuthGroupFile /etc/httpd/conf/group Require user user1 user2 </Directory>
DirectiveRole
Options IndexesLists the directory content if there is no index.html.
AllowOverride NoneProtection can only be changed from the main configuration file.
AuthType BasicType of authentication.
AuthNameText shown in the login dialog box.
Require userRestricts access to specific users.

User and group creation

  1. Create the password file: htpasswd -c /etc/httpd/conf/passwd [username] (drop -c for the next users).
  2. Create the group file /etc/httpd/conf/group in the format groupname: user1 user2 user3.
  3. Edit httpd.conf to test password access for users, then for a group (Require group).
Show this to the teacher to validate your points!

05Links

Complete Apache documentation: httpd.apache.org/docs/2.4